home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / news / thor / hd-install / thor.lha / rexx / BBSRead / CopyMessage.br < prev    next >
Text File  |  1997-08-29  |  7KB  |  240 lines

  1. /*
  2. ** $VER: CopyMessage.br 1.0 (20.5.97)
  3. ** by Eirik Nicolai Synnes
  4. **
  5. ** See SortMail.guide for documentation
  6. **
  7. */
  8.  
  9. options results
  10. options failat 31
  11.  
  12. parse arg arguments
  13.  
  14.  
  15. /*
  16. ** Initialize some variables
  17. */
  18.  
  19. version  = subword(sourceline(2), 4, 1)
  20.  
  21. template = 'SYSTEM/A,CONFERENCE/A,MSGNO/A,DESTCONF/A,DESTSYS/K,REPLYADDR/K'
  22.  
  23. CDB_MARK_OWN_MSGS      = 22           /* Also mark messages from user when adding messages. */
  24. CDF_NOT_ON_BBS         = '00008000'x  /* This conference is not on the bbs. */
  25.  
  26. CDNT_MAILFOLDER        = 3  /* This conference is a virtual mail folder */
  27.  
  28. MDB_READ               =  0  /* Message is read. */
  29. MDB_REPLIED            =  1  /* Message is replied. */
  30. MDB_PRIVATE            =  2  /* Message is private. */
  31. MDB_DELETED            =  5  /* Message is deleted. */
  32. MDB_KEEP               =  7  /* Keep message. Message will not be deleted during conference packing. */
  33. MDB_MARKED             = 10  /* Message is marked.  */
  34. MDB_URGENT             = 11  /* Message is urgent.    */
  35. MDB_IMPORTANT          = 12  /* Message is important. */
  36. MDB_SUPERMARKED        = 13  /* Message will not be unmarked as long as this flag is set. */
  37. MDB_CONFIDENTIAL       = 17  /* Message is confidential. */
  38.  
  39.  
  40. /*
  41. ** Find/open BBSREAD ARexx port
  42. */
  43.  
  44. if ~show('P', 'BBSREAD') then do
  45.     address(command)
  46.     'Run >NIL: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  47.     if exists('SYS:RexxC/WaitForPort') then 'SYS:RexxC/WaitForPort BBSREAD'
  48.     else 'WaitForPort BBSREAD'
  49.     if (rc = 5) then do; say 'Could not open BBSREAD''s ARexx port.'; exit(30); end
  50.     if (rc ~= 0) then do; say 'Could not find SYS:Rexxc/WaitForPort.'; exit(30); end
  51.     end
  52.  
  53.  
  54. /*
  55. ** Give template if arguments = '?' or empty
  56. */
  57.  
  58. if (arguments = '?') | (arguments = '') then do
  59.     say 'Usage: 'template
  60.     say 'CopyMessage.br is an external script for SortMail.'
  61.     exit(5)
  62.     end
  63.  
  64. address(bbsread)
  65. 'READARGS "'template'" 'args' CMDLINE 'arguments
  66. if (rc ~= 0) then do
  67.     say BBSREAD.LASTERROR
  68.     say 'Template: 'template
  69.     say 'CopyMessage.br is an external script for SortMail.'
  70.     exit(5)
  71.     end
  72.  
  73.  
  74. /*
  75. ** Utilize BBSRead's copyback buffer
  76. */
  77.  
  78. address(bbsread)
  79. 'BUFMODE COPYBACK'
  80.  
  81. /*
  82. ** Read message's header and text stems, exit if it's deleted
  83. */
  84.  
  85. 'READBRMESSAGE "'args.SYSTEM'" "'args.CONFERENCE'" 'args.MSGNO' HEADSTEM 'head' DATASTEM 'data' TEXTSTEM 'text
  86. if (rc ~= 0) then signal error
  87.  
  88. if (bittst(data.FLAGS, MDB_DELETED)) then do; myerr = 'Message was deleted.'; rc = 20; signal error; end
  89.  
  90.  
  91. /*
  92. ** Create header for new message
  93. */
  94.  
  95. text.fromname = head.FROMNAME
  96. if (symbol('head.FROMADDR') = 'VAR')        then text.fromaddr        = head.FROMADDR
  97. if (symbol('head.TONAME') = 'VAR')          then text.toname          = head.TONAME
  98. if (symbol('head.TOADDR') = 'VAR')          then text.toaddr          = head.TOADDR
  99. if (symbol('head.MSGID') = 'VAR')           then text.msgid           = head.MSGID
  100. if (symbol('head.REFID') = 'VAR')           then text.refid           = head.REFID
  101. if (symbol('head.CREATIONDATE') = 'VAR')    then text.creationdate    = head.CREATIONDATE
  102. if (symbol('head.CREATIONDATETXT') = 'VAR') then text.creationdatetxt = head.CREATIONDATETXT
  103. if (symbol('head.SUBJECT') = 'VAR')         then text.subject         = head.SUBJECT
  104.  
  105. text.replyconf = args.CONFERENCE
  106.  
  107.  
  108. /*
  109. ** Find a reply address from the arguments or the original message
  110. */
  111.  
  112. drop text.replyname
  113. if (symbol('args.REPLYADDR') ~= 'VAR') then do
  114.     if (symbol('text.REPLYADDR') ~= 'VAR') then do
  115.         text.replyaddr = head.FROMADDR
  116.         if (symbol('head.FROMNAME') = 'VAR') then text.replyname = head.FROMNAME
  117.         end
  118.     end
  119. else text.replyaddr = args.REPLYADDR
  120.  
  121.  
  122. /*
  123. ** Make sure args.DESTSYS contains something and get system configuration
  124. ** for destination
  125. */
  126.  
  127. if (symbol('args.DESTSYS') ~= 'VAR') then args.DESTSYS = args.SYSTEM
  128.  
  129. 'GETBBSDATA "'args.DESTSYS'" 'bbsdata
  130. if (rc ~= 0) then signal error
  131.  
  132.  
  133. /*
  134. ** See if the conference the msg will be written to exists
  135. */
  136.  
  137. 'GETCONFLIST BBSNAME "'args.DESTSYS'" STEM 'conflist
  138. if (rc ~= 0) then signal error
  139.  
  140. do n = 1 to conflist.COUNT + 1 while upper(args.DESTCONF) ~= upper(conflist.n)
  141.     if (n = conflist.COUNT + 1) then do
  142.         /* Create the new conference */
  143.         'CONFIGCONF "'args.DESTSYS'" "'args.DESTCONF'" SET 'c2x(CDF_NOT_ON_BBS)' CONFNETTYPE 'CDNT_MAILFOLDER
  144.         if (rc ~= 0) then signal error
  145.         end
  146.     end
  147.  
  148. drop conflist.
  149.  
  150.  
  151. /*
  152. ** Set the selected message flags
  153. */
  154.  
  155. writeflags = ''
  156. if (bittst(data.FLAGS, MDB_READ))         then writeflags = writeflags || 'READ '
  157. if (bittst(data.FLAGS, MDB_PRIVATE))      then writeflags = writeflags || 'PRIVATE '
  158. if (bittst(data.FLAGS, MDB_URGENT))       then writeflags = writeflags || 'URGENT '
  159. if (bittst(data.FLAGS, MDB_IMPORTANT))    then writeflags = writeflags || 'IMPORTANT '
  160. if (bittst(data.FLAGS, MDB_CONFIDENTIAL)) then writeflags = writeflags || 'CONFIDENTIAL '
  161.  
  162. updateflags = ''
  163. if (bittst(data.flags,  MDB_REPLIED))     then updateflags = updateflags || 'SETREPLIED '
  164. if (bittst(data.flags,  MDB_KEEP))        then updateflags = updateflags || 'SETKEEP '
  165. if (bittst(data.flags,  MDB_SUPERMARKED)) then updateflags = updateflags || 'SETSUPERUNREAD '
  166. if (symbol('data.HAZELEVEL') = 'VAR') & (data.HAZELEVEL > 0) then updateflags = updateflags || 'HAZELEVEL 'data.HAZELEVEL' '
  167.  
  168.  
  169. /*
  170. ** Mark message as unread only if Show own messages is not activated
  171. */
  172.  
  173. 'GETCONFDATA "'args.DESTSYS'" "'args.DESTCONF'" STEM 'confdata
  174. if (rc ~= 0) then signal error
  175.  
  176. if ~(bittst(confdata.FLAGS, CDB_MARK_OWN_MSGS)) & (upper(head.FROMADDR) = upper(bbsdata.EMAILADDR)) then writeflags = writeflags || 'DONTMARKMESSAGE '
  177.  
  178. if (confdata.CONFTYPE ~= CDNT_MAILFOLDER) then do
  179.     'CONFIGCONF "'args.DESTSYS'" "'args.DESTCONF'" SET 'c2x(CDF_NOT_ON_BBS)' CONFNETTYPE 'CDNT_MAILFOLDER
  180.     if (rc ~= 0) then signal error        
  181.     end
  182.  
  183. /*
  184. ** Write the message
  185. */
  186.  
  187. address(bbsread)
  188. 'WRITEBRMESSAGE "'args.DESTSYS'" "'args.DESTCONF'" STEM 'text' 'writeflags
  189. if (rc ~= 0) then signal error
  190. msgnr = result
  191.  
  192.  
  193. /*
  194. ** If the new message's number is -1 then it was caught by a kill
  195. */
  196.  
  197. if (msgnr ~= -1) then do
  198.  
  199.     /*
  200.     ** Give the new message it's flags
  201.     */
  202.  
  203.     if (updateflags ~= '') then do
  204.         'UPDATEBRMESSAGE "'args.DESTSYS'" "'args.DESTCONF'" 'msgnr' 'updateflags
  205.         if (rc ~= 0) then signal error
  206.         end
  207.     end
  208.  
  209. returned = 0; signal cleanup
  210.  
  211.  
  212. /*
  213. ** Some error detection stuff
  214. */
  215.  
  216. error:
  217. syntax:
  218.  
  219. returned = rc
  220.  
  221. select
  222.     when symbol('BBSREAD.LASTERROR') = 'VAR' then say 'Line 'sigl' returned 'returned': 'BBSREAD.LASTERROR
  223.     when symbol('myerr') = 'VAR' then say 'Line 'sigl' returned 'returned': 'myerr
  224.     otherwise say 'Line 'sigl' returned 'returned': 'errortext(returned)
  225.     end
  226.  
  227. break_c:
  228. halt:
  229. cleanup:
  230.  
  231.  
  232. /*
  233. ** Turn off copyback buffer
  234. */
  235.  
  236. address(bbsread)
  237. 'BUFMODE ENDCOPYBACK'
  238.  
  239. exit(returned)
  240.